package com.zyk.scaffold.user.controller.tenantfunction;


import com.zyk.scaffold.common.basic.BasicConstants;
import com.zyk.scaffold.core.domain.Result;
import com.zyk.scaffold.common.utils.BeanCopyUtil;
import com.zyk.scaffold.user.domain.FunctionMessage;
import com.zyk.scaffold.user.service.TenantFunctionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 租户-功能表 前端控制器
 * </p>
 *
 * @author zhouyk
 * @since 2022-11-04
 */
@Api(tags = "租户-功能-API")
@RestController
@RequestMapping("/tenant-function")
public class TenantFunctionController {

    @Autowired
    private TenantFunctionService tenantFunctionService;

    @ApiOperation("租户-功能列表")
    @PostMapping("/list")
    public Result<List<FunctionMessageResp>> listFunction(@RequestHeader(BasicConstants.HEADER_TENANT_CODE) String tenantCode) {
        List<FunctionMessage> functionMessages = tenantFunctionService.queryTenantCodesFunction(Arrays.asList(tenantCode));
        List<FunctionMessageResp> functionMessageResps = BeanCopyUtil.copyListProperties(functionMessages, FunctionMessageResp::new);
        return Result.ok(functionMessageResps);
    }
}
